<template>
	<el-main>
		<el-card class="box-card" shadow="never">
			<div class="search-box">
				<el-form :inline="true" :model="searchForm" class="demo-form-inline">
					<el-form-item label="状态">
						<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
							<el-option label="待确认" value="0"></el-option>
							<el-option label="拼团中" value="1"></el-option>
							<el-option label="成团" value="2"></el-option>
							<el-option label="取消" value="3"></el-option>
							<el-option label="超时关闭" value="4"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item label="开团时间">
						<el-date-picker
							v-model="searchForm.time"
							type="daterange"
							value-format="YYYY-MM-DD"
							range-separator="至"
							start-placeholder="开始日期"
							end-placeholder="结束日期">
						</el-date-picker>
					</el-form-item>

					<el-form-item>
						<el-button type="primary" @click="onSubmit" icon="el-icon-search" >查询</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div style="width:100%;height:0;border-bottom:#E4E7ED 1px dashed;margin-bottom: 10px"></div>
			<el-table
				:data="tableData"
				style="width: 100%;">
				<el-table-column
					prop="id"
					label="ID">
				</el-table-column>
				<el-table-column
					width="160"
					label="团长">
					<template #default="scope">
						<div style="display: flex;align-items: center">
							<img :src="scope.row.leader_avatar" style="margin-right: 10px;width: 40px;height: 40px;"/>
							ID: {{ scope.row.leader_id }} | {{ scope.row.leader_name }}
						</div>
					</template>
				</el-table-column>
				<el-table-column
					prop="goodsInfo.name"
					width="500"
					label="商品名">
				</el-table-column>
				<el-table-column
					prop="total_num"
					label="成团人数">
				</el-table-column>
				<el-table-column
					label="参团人数">
					<template #default="scope">
						{{ scope.row.total_num - scope.row.left_num }}
					</template>
				</el-table-column>
				<el-table-column
					width="160"
					prop="close_time"
					label="结束时间">
				</el-table-column>
				<el-table-column
					label="状态">
					<template #default="scope">
						<el-tag v-if="scope.row.status == 0">待确认</el-tag>
						<el-tag type="success" v-if="scope.row.status == 1">拼团中</el-tag>
						<el-tag type="success" v-if="scope.row.status == 2">成团</el-tag>
						<el-tag type="danger" v-if="scope.row.status == 3">取消</el-tag>
						<el-tag type="danger" v-if="scope.row.status == 4">超时关闭</el-tag>
					</template>
				</el-table-column>
				<el-table-column
					prop="operation"
					label="操作">
					<template #default="scope">
						<el-button @click="handleDetail(scope.row)" type="text" size="small">详情</el-button>
					</template>
				</el-table-column>
			</el-table>

			<Pages :form="searchForm" :page-obj="page" @pageChange="handlePageChange" @pageJump="getList"></Pages>
		</el-card>

		<detail-dialog v-if="dialogVisible" ref="detailDialog" @closed="dialogVisible=false" :close-on-click-modal="false"></detail-dialog>
	</el-main>
</template>

<script>
import detailDialog from './detail'
import Pages from "@/components/pages/index.vue";

export default {
	name: "groupon_order",
	components: {
		Pages,
		detailDialog
	},
	data() {
		return {
			searchForm: {
				status: '',
				time: '',
				limit: 15,
				page: 1
			},
			dialogVisible: false,
			page: {
				total: 0
			},
			tableData: [],
		}
	},
	mounted() {
		this.getList()
	},
	methods: {
		// 获取列表
		async getList() {
			let res = await this.$API.groupon.orderList.get(this.searchForm)
			this.tableData = res.data.data
			this.page.total = res.data.total
		},
		// 搜索
		onSubmit() {
			this.searchForm.page = 1
			this.getList()
		},
		// 分页
		handlePageChange(page) {
			this.searchForm.page = page
			this.getList()
		},
		handleDetail(row) {
			this.dialogVisible = true

			this.$nextTick(() => {
				this.$refs.detailDialog.open().setData(row)
			})
		}
	}
}
</script>

<style scoped>

</style>
